package com.example.administrator.learnapp2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

//第一个界面
public class MainActivity extends AppCompatActivity {
    TextView num1;
    TextView num2;
    TextView add;
    TextView eq;
    TextView result;

    int a;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main_activity);

        num1 = this.findViewById(R.id.num1);
        num2 = this.findViewById(R.id.num2);
        add = this.findViewById(R.id.add);
        eq = this.findViewById(R.id.eq);
        result = this.findViewById(R.id.result);

        num1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                result.setText(result.getText()+"1");
            }
        });

        num2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                result.setText(result.getText()+"2");
            }
        });

        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               a = Integer.parseInt(result.getText().toString());
               result.setText("");
            }
        });

        eq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Integer b = a + Integer.parseInt(result.getText().toString());
                result.setText(b.toString());
            }
        });

    }
}







